<?php

namespace Biz\model\settlement;


class WillSettlement extends BaseAccountTransaction
{

    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_settlement';

    const _DATABASE_ = 'shop_settlement';

    const _TABLE_NAME = 'will_settlement';

    public static function addData($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('数据库操作错误');
        }
        return true;
    }

    public static function getList($orderNos, $startTime, $endTime)
    {
        $where['AND']['order_no'] = $orderNos;
        $where['AND']['status'] = self::STATUS_NORMAL;
        if ($startTime && $endTime) {
            $where['operate_time[>=]'] = $startTime;
            $where['operate_time[<=]'] = $endTime;
        }
        $where['ORDER'] = ['operate_time' => 'DESC'];
        $list = self::select('*', $where);
        self::formatList($list);
        return $list;
    }

    public static function formatList(&$list)
    {
        foreach ($list as &$row) {
            self::formatInfo($row);
        }
    }

    public static function formatInfo(&$info)
    {
        if (empty($info)) {
            return;
        }
        if ($info['operate_type'] == self::OPERATE_TYPE_SYS) {
            $info['operator'] = self::$operateTypeDesc[self::OPERATE_TYPE_SYS];
        } else if ($info['operate_type'] == self::OPERATE_TYPE_ADMIN) {
            $info['operator'] = self::$operateTypeDesc[self::OPERATE_TYPE_ADMIN];
        } else if ($info['operate_type'] == self::OPERATE_TYPE_SHOP) {
            $info['operator'] = self::$operateTypeDesc[self::OPERATE_TYPE_SHOP];
        } else if ($info['operate_type'] == self::OPERATE_TYPE_USER) {
            $info['operator'] = self::$operateTypeDesc[self::OPERATE_TYPE_USER];
        }
        foreach ($info as $key => &$value) {
            switch ($key) {
                case 'transaction_type':
                    $info['transaction_type_desc'] = self::$transactionTypeDesc[$value];
                    break;
            }
        }

    }
}
